/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "dal_cyclonedds/utils/ParticipantGuidMap.hpp"

TEST(map_test, test_participant_guid_map)
{
    dal_guid_t guid_1;
    memset(&guid_1.entity_id, 0x55, ENTITYID_SIZE);
    memset(&guid_1.guidprefix, 0xEE, GUIDPREFIX_SIZE);

    dal_guid_t guid_2;
    memset(&guid_2.entity_id, 0x22, ENTITYID_SIZE);
    memset(&guid_2.guidprefix, 0xCC, GUIDPREFIX_SIZE);

    DalGuidForMap guid_fro_map_1 = DalGuidForMap(guid_1);
    DalGuidForMap guid_fro_map_2 = DalGuidForMap(guid_2);

    ParticipantGuidMapInsert(guid_fro_map_1, "name_1");
    std::string name_1;
    EXPECT_EQ(ParticipantGuidMapFind(DalGuidForMap(guid_1), name_1), true);
    EXPECT_STREQ(name_1.c_str(), "name_1");

    std::string name_2;
    EXPECT_EQ(ParticipantGuidMapFind(DalGuidForMap(guid_2), name_2), false);

    ParticipantGuidMapErase(DalGuidForMap(guid_1));
    std::string name_1_t;
    EXPECT_EQ(ParticipantGuidMapFind(DalGuidForMap(guid_1), name_1_t), false);
}
